<?php
// This page is used to retrieve url information from alexa server


// Format example:
// url_info.php?type=url	[url|query] default: query
//			   &q=www.google.com 
//			   &action=UrlInfo [All|UrlInfo|History|SitesLinkingIn]
//			   &response_group=SiteData


require_once("alexa_info.php");
require_once("google_search.php");


//response group
$action = $_GET['action'];
$response_group = $_GET['response_group'];

$final_result= array();
// determine request type
if($_GET['type']=="url"){
	$alexa = new alexa_info(urldecode($_GET["q"]));
	if($action == "All")
		$url_info = $alexa->get_all_info();
	else{
		$alexa->make_URL_info_request($action,$response_group);
		$url_info = $alexa->get_result_array();
	}
	$final_result["url"] = urlencode($_GET["q"]);
	$final_result["info"] = $url_info;	
}
else{
	//url array need to be retrieve 
	$url_array = google_search($_GET['q']);
	$final_result = array();
	$index=0;
	foreach($url_array as $url){
		$alexa = new alexa_info($url['url']);
		if($action == "All")
			$url_info = $alexa->get_all_info();
		else{
			$alexa->make_URL_info_request($action,$response_group);
			$url_info = $alexa->get_result_array();
		}
		array_push($final_result,array("id"=>$index,"url"=>urlencode($url['url']),"info"=>$url_info));
		$index++;
	}	

	


}

	// ajax send back
	echo json_encode($final_result);


?>